<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/29
 * Time: 14:27
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\common\business\Theatre as BusObj;
use app\common\lib\Show;
use app\common\lib\Status;
use think\App;

class Theatre extends Base
{
    protected BusObj $busObj;

    public function __construct(App $app)
    {
        $this->busObj = new BusObj();
        parent::__construct($app);
    }

    public function getTheatreById()
    {
        $id = $this->request->param('id', 0, 'intval');
        $openid = $this->request->param('openid', '', 'trim');
        if ($id == 0) {
            return Show::json_show(Status::mini_error, "错误");
        }
        try {
            $lists = $this->busObj->getBaseById($id, '*,thumb as root_path_thumb,venue as get_venue_address,performer as get_performer_head');
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        //查询是否收藏
        try {
            $coll = (new \app\common\business\Collection())->getCollectionByOpenidId($lists['id'], $openid);
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        if($coll){
            $coll = 1;
        }else{
            $coll = 0;
        }
        //查询是否点赞
        try {
            $fabulous = (new \app\common\business\Fabulous())->getFabulousByInfo($id, $openid);
        }catch (\Exception $e){
            return Show::json_show(Status::mini_error,$e->getMessage());
        }
        if(!$fabulous){
            $fa = 0;
        }else{
            if($fabulous['state'] == 1){
                $fa = 1;
            }else{
                $fa = 0;
            }
        }
        $result = [
            "lists" => $lists,
            "coll" => $coll,
            "fa"=>$fa
        ];
        return Show::json_show(Status::mini_normal, "ok", $result);
    }

    /**
     * @return \think\response\Json
     */
    public function getTheatreByList()
    {
        //场次id
        $theatre_id = $this->request->param('id', 0, 'intval');
        if ($theatre_id == 0) {
            return Show::json_show(Status::mini_error, "请稍后重试");
        }
        try {
            $lists = $this->busObj->getTheatreByList($theatre_id);
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        return Show::json_show(Status::mini_normal, "ok", $lists);
    }

}